package me.sunpeng.principle.ocp.improve;

/**
 * @author sp
 */
public class Ocp {
    public static void main(String[] args) {
        GraphEditor graphEditor = new GraphEditor();
        graphEditor.drawShape(new Rectangle());
        graphEditor.drawShape(new Circle());
    }
}

//用于绘图的类[使用方]
class GraphEditor {
    //接受Shape对象，调用draw方法
    public void drawShape(Shape s) {
        s.draw();
    }

}

//Shape类，基类 可扩展
abstract class Shape {
    int m_type;

    public abstract void draw();

}

class Rectangle extends Shape {
    Rectangle() {
        super.m_type = 1;
    }

    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}

class Circle extends Shape {
    Circle() {
        super.m_type = 2;
    }

    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}